package com.sushe.service;

import com.sushe.dao.RegisterDao;
import com.sushe.service.jiekou.RegisterService;

import java.sql.SQLException;
import java.util.Scanner;

public class RegisterServiceImpl implements RegisterService {

    private RegisterDao registerDao=new RegisterDao();
    @Override
    public void register() throws SQLException, ClassNotFoundException {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入要注册的用户名");
        String username=sc.nextLine();
        boolean flag;
        flag=registerDao.select(username);
        if(flag){
            System.out.println("该用户已存在，请返回登陆！");
            return;
        }
        while(true){
            System.out.println("请输入该用户名的密码");
            String password=sc.nextLine();
            System.out.println("请再次输入密码进行确认");
            String password2=sc.nextLine();
            if(password.equals(password2)){
                registerDao.addUser(username,password);
                System.out.println("注册成功！");
                return;
            }
            System.out.println("密码不一致！请重新输入");
        }
    }
}
